package com.lexed.demo3;

import java.util.*;

public class TestDemo {
	public static void main(String[] args) {

		// 1. 创建牌
		List<Poker> l1 = new ArrayList<>();
		for (int i = 1; i <= 52; i++) {
			Poker p1 = new Poker(i);
			l1.add(p1);
		}
		l1.add(new Poker(53));
		l1.add(new Poker(54));

		System.out.println("顺牌：" + l1);

		// 2. 打乱
		Collections.shuffle(l1);
		Collections.shuffle(l1);
		System.out.println("洗牌：" + l1);

		// 3. 发牌
		List<Poker> player1 = new ArrayList<>();
		List<Poker> player2 = new ArrayList<>();
		List<Poker> player3 = new ArrayList<>();
		for (int i = 0; i < 17; i++) {
			player1.add(l1.remove(0));
			player2.add(l1.remove(0));
			player3.add(l1.remove(0));
		}
		System.out.println("玩家一：" + player1);
		System.out.println("玩家二：" + player2);
		System.out.println("玩家三：" + player3);
		System.out.println("底牌：" + l1);

		// 4. 整理牌
		// 玩家一
		Collections.sort(player1, new Comparator<Poker>() {

			@Override
			public int compare(Poker o1, Poker o2) {
				// 牌按大小顺牌
				if (o1.getNum() < o2.getNum()) {
					return 1;
				} else if (o1.getNum() > o2.getNum()) {
					return -1;
				}
				return 0;
			}
		});

		System.out.println("玩家一顺牌：" + player1);
		// 玩家二
		Collections.sort(player2, new Comparator<Poker>() {

			@Override
			public int compare(Poker o1, Poker o2) {
				// 牌按大小顺牌
				if (o1.getNum() < o2.getNum()) {
					return 1;
				} else if (o1.getNum() > o2.getNum()) {
					return -1;
				}
				return 0;
			}
		});

		System.out.println("玩家二顺牌：" + player2);
		// 玩家三
		Collections.sort(player3, new Comparator<Poker>() {

			@Override
			public int compare(Poker o1, Poker o2) {
				// 牌按大小顺牌
				if (o1.getNum() < o2.getNum()) {
					return 1;
				} else if (o1.getNum() > o2.getNum()) {
					return -1;
				}
				return 0;
			}
		});

		System.out.println("玩家三顺牌：" + player3);
	}

}
